package cn.stylefeng.guns.sys.modular.tao.service.serviceImpl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.tao.entity.TaoHelps;
import cn.stylefeng.guns.sys.modular.tao.mapper.TaoHelpMappers;
import cn.stylefeng.guns.sys.modular.tao.model.params.TaoHelpParams;
import cn.stylefeng.guns.sys.modular.tao.model.result.TaoHelpResults;
import cn.stylefeng.guns.sys.modular.tao.service.TaoHelpServices;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 帮助中心 服务实现类
 * </p>
 *
 * @author shiboshi
 * @since 2019-10-22
 */
@Service
public class TaoHelpServiceImpls extends ServiceImpl<TaoHelpMappers, TaoHelps> implements TaoHelpServices {

    @Autowired
    private TaoHelpMappers taoHelpMapper;


    @Override
    public void add(TaoHelpParams param){
        TaoHelps entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaoHelpParams param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(TaoHelpParams param){
        TaoHelps oldEntity = getOldEntity(param);
        TaoHelps newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaoHelpResults findBySpec(TaoHelpParams param){
        return null;
    }

    @Override
    public List<TaoHelpResults> findListBySpec(TaoHelpParams param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaoHelpParams param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(TaoHelpParams param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaoHelps getOldEntity(TaoHelpParams param) {
        return this.getById(getKey(param));
    }

    private TaoHelps getEntity(TaoHelpParams param) {
        TaoHelps entity = new TaoHelps();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }



    /**
     * 查询做大值
     */
    public int idMax(){
        return taoHelpMapper.idMax();
    }


    /**
     * 新增接口
     */
    public void addTaoHelp(TaoHelpParams taoHelpParam){
        this.taoHelpMapper.addTaoHelp(taoHelpParam);
    }


    /**
     * 删除接口
     */
    public void deleteTaoHelp(@Param("id") Integer id){
        this.taoHelpMapper.deleteTaoHelp(id);
    }


    /**
     * 查看详情接口
     */
    public TaoHelps QueryHelp(@Param("id") String id){
        return taoHelpMapper.QueryHelp(id);
    }


    /**
     * 修改数据接口
     */
    public void updateHelp(TaoHelpParams taoHelpParam){
        this.taoHelpMapper.updateHelp(taoHelpParam);
    }



}
